<template>
  <div id="item-bank" class="jx-content">
    <el-dialog width="850" class="dialog-import-questions" title="导入试题" :visible.sync="dialogQuestion">
      <div class="dialog-content">
        <div class="question-title">关于媒体文件存储有点说法正确的是？</div>
        <div class="question-chose">A：
          <span class="question-flex">关于媒体文件存储有点说法正确的是，</span>
        </div>
        <div class="question-chose">B：
          <span class="question-flex">关于媒体文件存储有点说法正确的是关于媒体文件存储有点说法正确的是，关于媒体文件存储有点说法正确的是，关于媒体文件存储有点说法正确的是，关于媒体文件存储有点说法正确的是，关于媒体文件存储有点说法正确的是，关于媒体文件存储有点说法正确的是，关于媒体文件存储有点说法正确的是，关于媒体文件存储有点说法正确的是，</span>
        </div>
        <div class="question-chose">C：
          <span class="question-flex">关于媒体文件存储有点说法正确的是</span>
        </div>
        <div class="question-chose">D：
          <span class="question-flex">关于媒体文件存储有点说法正确的是</span>
        </div>
        <div class="question-answer">答案：
          <span class="chose">A</span>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="button-style" @click="dialogQuestion = false">确 定</el-button>
      </span>
    </el-dialog>
    <div>
      <el-tabs v-model="activeName" @tab-click="tabHandleClick">
        <el-tab-pane name="first">
          <span slot="label">
            <el-badge :value="choseTableData.length" class="item">选择题目</el-badge>
          </span>
          <div class="search-box">
            <el-form :inline="true" ref="searchForm" :model="searchForm" label-width="80px">
              <el-form-item label="关键词">
                <el-input v-model="searchForm.name"></el-input>
              </el-form-item>
              <el-form-item label="课程">
                <el-select v-model="searchForm.region" placeholder>
                  <el-option label="区域一" value="shanghai"></el-option>
                  <el-option label="区域二" value="beijing"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="章节">
                <el-select v-model="searchForm.region" placeholder>
                  <el-option label="区域一" value="shanghai"></el-option>
                  <el-option label="区域二" value="beijing"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="题目类型">
                <el-select v-model="searchForm.region" placeholder>
                  <el-option label="区域一区域一区域一区域一区域一区域一区域一区域一" value="shanghai"></el-option>
                  <el-option label="区域二" value="beijing"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <div class="button-style">搜 索</div>
              </el-form-item>
            </el-form>
          </div>
          <el-table ref="tableData" :data="tableData" @selection-change="handleSelectionChange" style="width: 100%" v-if="activeName === 'first'">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="date" label="试题题目"></el-table-column>
            <el-table-column prop="name" label="试题类型" width="180"></el-table-column>
            <el-table-column prop="name" label="课程" width="180"></el-table-column>
            <el-table-column prop="address" label="章节"></el-table-column>
            <el-table-column fixed="right" label="操作" width="200">
              <template slot-scope="scope">
                <el-button @click="dialogQuestion = true" type="text" size="small">预览</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane class="second" label="已选择" name="second">
          <div class="search-box">
            <el-form :inline="true" ref="searchForm" :model="searchForm" label-width="80px">
              <el-form-item>
                <div class="button-style" @click="choseDel">删 除</div>
              </el-form-item>
            </el-form>
          </div>
          <el-table ref="choseTableData" :data="choseTableData" @selection-change="choseHandleSelectionChange" style="width: 100%" v-if="activeName === 'second'">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="date" label="试题题目"></el-table-column>
            <el-table-column prop="name" label="试题类型" width="180"></el-table-column>
            <el-table-column prop="name" label="课程" width="180"></el-table-column>
            <el-table-column prop="address" label="章节"></el-table-column>
            <el-table-column fixed="right" label="操作" width="200">
              <template slot-scope="scope">
                <el-button @click="dialogQuestion = true" type="text" size="small">预览</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<script>
import $ from "jquery";
export default {
  data() {
    return {
      //试题预览
      dialogQuestion: false,
      activeName: "first",
      searchForm: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: ""
      },
      tableData: [
        {
          id: 1,
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          laiyuan: "laiyuan"
        },
        {
          id: 2,
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
          laiyuan: "laiyuan"
        },
        {
          id: 3,
          date: "2016-05-01",
          name: "王小虎",
          address:
            "上海市普陀区金沙江路 1519 弄上海市普陀区金沙江路 1519 弄上海市普陀区金沙江路 1519 弄",
          laiyuan: "laiyuan"
        },
        {
          id: 4,
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
          laiyuan: "laiyuan"
        }
      ],
      choseTableData: [],
      delChoseTableData: []
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.addRowIndex();
    },
    addRowIndex() {
      let tableData = this.tableData;
      $.each(tableData, function(i, d) {
        d.index = i;
      });
      //console.log(tableData);
    },
    handleSizeChange() {},
    handleCurrentChange() {},
    //选择题目-checkbox
    handleSelectionChange(val) {
      this.choseTableData = val;
    },
    //已选择-checkbox
    choseHandleSelectionChange(val) {
      this.delChoseTableData = val;
    },
    //已选择-删除
    choseDel() {
      //选中数组
      let delChoseTableData = this.delChoseTableData;
      //取消选中
      this.closeRowSelection(delChoseTableData);
    },
    //取消选中，传对象数组
    closeRowSelection(rows) {
      console.log(rows);
      if (rows) {
        rows.forEach(row => {
          console.log(row);
          this.$refs.tableData.toggleRowSelection(row, false);
        });
      } else {
        this.$refs.tableData.clearSelection();
      }
    },
    //已选择-取消选择
    toggleSelection(rows) {
      // if (rows) {
      //   rows.forEach(row => {
      //     this.$refs.multipleTable.toggleRowSelection(row);
      //   });
      // } else {
      //   this.$refs.multipleTable.clearSelection();
      // }
    },
    tabHandleClick(tab, event) {
      console.log(tab, event);
    }
  }
};
</script>
<style lang="scss">
@import "../../../styles/layout/color_variables";
#item-bank {
  width: 1200px;
  margin: 50px auto;
  .dialog-import-questions {
    .dialog-content {
      text-align: left;
      padding: 20px 64px 0;
      .question-title {
        font-weight: bold;
        font-size: 16px;
        margin-bottom: 20px;
      }
      .question-chose {
        font-size: 14px;
        line-height: 24px;
        padding: 6px 0;
        display: flex;
        .question-flex {
          flex: 1;
        }
      }
      .question-answer {
        font-size: 16px;
        .chose {
          font-size: 18px;
          color: #385899;
          vertical-align: -2px;
        }
        margin-top: 20px;
      }
    }
    .el-dialog__footer {
      text-align: center;
    }
  }
  .el-badge__content {
    right: -10px;
    z-index: 1;
  }
  .el-tabs__nav-scroll {
    overflow: initial;
    &:after {
      content: "";
      display: block;
      clear: both;
    }
  }
  .el-tabs__nav-wrap {
    overflow: initial;
  }
  .el-tabs__nav-wrap::after {
    background: none;
  }
  .el-tabs__item {
    border: 1px solid #d9d9d9;
    padding: 0 20px;
    height: 40px;
    line-height: 40px;
    color: #474747;
  }
  .el-tabs__item.is-active {
    background: #1277eb;
    color: #fff;
  }
  .el-tabs__active-bar {
    background: none;
  }
  #tab-first {
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
  }
  #tab-second {
    position: relative;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
    margin-left:-1px;
  }
  .second .search-box {
    text-align: right;
  }
  .sub {
    background-color: #f56c6c;
    border-radius: 10px;
    color: #fff;
    display: inline-block;
    font-size: 12px;
    height: 18px;
    line-height: 18px;
    padding: 0 6px;
    text-align: center;
    white-space: nowrap;
    border: 1px solid #fff;
    z-index: 9;
    transform: translate(170px, -9px);
    position: absolute;
  }
}
</style>
